package rs.pnv.merchant.controller;

import java.util.List;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import rs.pnv.model.user.User;
import rs.pnv.service.UserService;

@Controller
@RequestMapping("/users")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String handleUserLoginGet() {
		return "";
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String handleUserLoginPost(@Valid @ModelAttribute("loginUser") User user, HttpSession session, Model model) {

		return "";
	}

	@RequestMapping(value = "/register", method = RequestMethod.GET)
	public String handleUserRegisterGet() {
		return "";
	}

	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public String handleUserRegisterPost() {
		return "";
	}

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String handleListAllUsersGet(Model model) {

		List<User> users = userService.findAll();

		model.addAttribute("usersList", users);

		return "users";
	}

	@RequestMapping(value = "/{username}", method = RequestMethod.GET)
	public String handleUsersViewGet(@PathVariable String username, Model model) {

		User user = userService.findByUsername(username);

		model.addAttribute("viewedUser", user);

		return "viewUser";
	}

}
